package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.dto.BaseException;
import cn.jiahua.hospital.dto.HospitalDto;
import cn.jiahua.hospital.mapper.HospitalMapper;
import cn.jiahua.hospital.pojo.Hospital;
import cn.jiahua.hospital.service.HospitalService;
import cn.jiahua.hospital.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

import javax.annotation.Resource;

@Service
public class HospitalServiceImpl implements HospitalService {

    @Resource
    private HospitalMapper hospitalMapper;

    @Override
    public HospitalDto getHospitalDtoById(Integer id) {
        return hospitalMapper.getHospitalDtoById(id);
    }

    @Override
    public HospitalDto getHospitalDtoById2(Integer id) {
        return hospitalMapper.getHospitalDtoById2(id);
    }

    @Override
    public Hospital getHospitalById(Integer id) {
        return hospitalMapper.getHospitalById(id);
    }

    @Override
    public List<Hospital> getHospitalListByMap(Map<String, Object> param) {
        return hospitalMapper.getHospitalListByMap(param);
    }

    @Override
    public Integer getHospitalCountByMap(Map<String, Object> param) {
        return hospitalMapper.getHospitalCountByMap(param);
    }

    @Override
    public Integer qdtxAddHospital(Hospital hospital) {
        return hospitalMapper.insertHospital(hospital);
    }

    @Override
    public Integer qdtxModifyHospital(Hospital hospital) {
        return hospitalMapper.updateHospital(hospital);
    }

    @Override
    public Integer qdtxDeleteHospitalById(Integer id) {
        return hospitalMapper.deleteHospitalById(id);
    }

    @Override
    public Integer qdtxBatchDeleteHospital(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return hospitalMapper.batchDeleteHospital(param);
    }

    @Override
    public Page<Hospital> queryHospitalPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = hospitalMapper.getHospitalCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<Hospital> hospitalList = hospitalMapper.getHospitalListByMap(param);
        page.setList(hospitalList);
        return page;
    }

    @Override
    public boolean hospitalLogin(String account, String password) {
        boolean flag = false;
        String password1 = hospitalMapper.getPassword(account);
        if (password1.equals(password)) {
            flag = true;
        }
        return flag;
    }

    @Override
    public int hospitalSelectCount(String hospitalName, Integer AddressId) {
        return hospitalMapper.hospitalSelectCount(hospitalName, AddressId);
    }

    @Override
    public List<Hospital> hospitalSelectPage(String hospitalName, Integer AddressId, Integer pageNo, Integer pageSize) {
        return hospitalMapper.hospitalSelectPage(hospitalName, AddressId, pageNo, pageSize);
    }

    @Override
    public List<Hospital> hospitalAttentionData(Integer pageNo, Integer pageSize) {
        return hospitalMapper.hospitalAttentionData(pageNo,pageSize);
    }

    @Override
    public List<HospitalDto> hospitalSelectPage2(String hospitalName, Integer AddressId, Integer pageNo, Integer pageSize) {
        return hospitalMapper.hospitalSelectPage2(hospitalName, AddressId, pageNo, pageSize);
    }

    @Override
    public int hospitalSelectCount2(String hospitalName, Integer AddressId) {
        return hospitalMapper.hospitalSelectCount2(hospitalName, AddressId);
    }

    @Override
    public List<HospitalDto> hospitalSelectPage3(String hospitalName, Integer AddressId, Integer pageNo, Integer pageSize) {
        return hospitalMapper.hospitalSelectPage3(hospitalName, AddressId, pageNo, pageSize);
    }

    @Override
    public int hospitalSelectCount3(String hospitalName, Integer AddressId) {
        return hospitalMapper.hospitalSelectCount3(hospitalName, AddressId);
    }

}